#include "widget.h"
#include "ui_widget.h"
#include <QLabel>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QLabel* lab1 = new QLabel(ui->tab);
    lab1->resize(100,100);
    lab1->setText("标签页1");

    QLabel* lab2 = new QLabel(ui->tab_2);
    lab2->resize(100,100);
    lab2->setText("标签页2");

}

void Widget::on_pushButton_clicked()
{
    int count = ui->tabWidget->count();
    // 创建新的标签页，标签页是QWidget
    QWidget* w = new QWidget;
    ui->tabWidget->addTab(w,"标签页" + QString::number(count+1));
    QLabel* lab = new QLabel(w);
    lab->resize(100,100);
    lab->setText("标签页" + QString::number(count+1));
    // 选中当前这个标签页
    ui->tabWidget->setCurrentIndex(count);

}

void Widget::on_pushButton_2_clicked()
{
    int index = ui->tabWidget->currentIndex();
    ui->tabWidget->removeTab(index);
}

Widget::~Widget()
{
    delete ui;
}



